package com.example.littleken.recyclerviewtext.Activitys;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;

import com.example.littleken.recyclerviewtext.Adapter.StageredAdapter;
import com.example.littleken.recyclerviewtext.R;

public class puRecyclerViewActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pu_recycler_view);
        recyclerView = (RecyclerView) findViewById(R.id.rv_pu);
        //设置layoutmanager
        //StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL)垂直布局，有2列
        // StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.HORIZONTAL)水平布局，有2行
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        recyclerView.addItemDecoration(new MyDecoration());
        recyclerView.setAdapter(new StageredAdapter(puRecyclerViewActivity.this));
    }
    class MyDecoration extends RecyclerView.ItemDecoration{
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            int gap = getResources().getDimensionPixelSize(R.dimen.dividerHeight);
            outRect.set(gap,gap,gap,gap);
        }
    }
}
